<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="测评表id:" prop="scaleId" label-width="90px">
        <el-input
          v-model="queryParams.scaleId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测评标题:" prop="scaleTitle" label-width="120px">
        <el-input
          v-model="queryParams.scaleTitle"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="登录账号:" prop="loginName" label-width="120px">
        <el-input
          v-model="queryParams.loginName"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称:" prop="userName" label-width="120px">
        <el-input
          v-model="queryParams.userName"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总分:" prop="countScore" label-width="90px">
        <el-input
          v-model="queryParams.countScore"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="因子分数:" prop="factorScore" label-width="90px">
        <el-input
          v-model="queryParams.factorScore"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="班级:" prop="classesName" label-width="120px">
        <el-input
          v-model="queryParams.classesName"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="所属学院:" prop="deptName" label-width="120px">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入学院"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:result_personal:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:result_personal:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:result_personal:remove']"
          >删除</el-button
        >
      </el-col>
      <span style="font-size: 0.3em">勾选数据导出指定列，否则为全部</span>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:result_personal:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="result_personalList"
      @selection-change="handleSelectionChange"
      tooltip-effect="dark myTooltips"
    >
      <el-table-column type="selection" width="50" align="center" />
      <!-- <el-table-column label="测评结果id" align="center" prop="resultId" /> -->
      <!-- <el-table-column label="测评量表id" align="center" prop="scaleId" /> -->
      <el-table-column label="测评量表名称" align="center" prop="scaleTitle" />
      <!-- <el-table-column label="用户id" align="center" prop="userId" /> -->
      <el-table-column label="用户昵称" align="center" prop="userName" />
      <!-- <el-table-column label="登录账号" align="center" prop="loginName" /> -->
      <!-- <el-table-column label="班级" align="center" prop="classesName" /> -->
      <!-- <el-table-column label="学院"  align="center" prop="deptName" /> -->
      <el-table-column label="总分" align="center" prop="countScore" />
      <el-table-column label="因子分数" align="center" prop="factorScore" />
      <el-table-column
        label="分数范围和结果提示"
        align="center"
        prop="resultContent"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="因子的分数范围及结果提示"
        align="center"
        prop="factorResult"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="用户选择数据"
        align="center"
        prop="userAnswer"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:result_personal:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:result_personal:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改个人测评成绩报告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="55rem" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="7rem">
        <el-form-item label="测评量表id:" prop="scaleId">
          <el-input v-model="form.scaleId" placeholder="请输入测评量表id" />
        </el-form-item>
        <el-form-item label="测评量表标题:" prop="scaleTitle">
          <el-input
            v-model="form.scaleTitle"
            placeholder="请输入测评量表标题"
          />
        </el-form-item>
        <el-form-item label="用户id:" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="登录账号:" prop="loginName">
          <el-input v-model="form.loginName" placeholder="请输入登录账号" />
        </el-form-item>
        <el-form-item label="用户昵称:" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户昵称" />
        </el-form-item>
        <!-- <el-form-item label="班级:" prop="classesName">
          <el-input v-model="form.classesName" placeholder="请输入班级" />
        </el-form-item> -->
        <!-- <el-form-item label="学院" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入学院" />
        </el-form-item> -->
        <el-form-item label="总分:" prop="countScore">
          <el-input v-model="form.countScore" placeholder="请输入总分" />
        </el-form-item>
        <el-form-item label="因子的分数:" prop="factorScore">
          <el-input v-model="form.factorScore" placeholder="请输入因子的分数" />
        </el-form-item>
        <el-form-item label="用户选择数据:" prop="userAnswer">
          <el-input
            v-model="form.userAnswer"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="分数范围和结果提示:" prop="resultContent">
          <el-input
            v-model="form.resultContent"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="因子的分数范围及结果提示:" prop="factorResult">
          <el-input
            v-model="form.factorResult"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listResult_personal,
  getResult_personal,
  delResult_personal,
  addResult_personal,
  updateResult_personal,
} from "@/api/mentalTest/personScore";

export default {
  name: "Score_Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 个人测评成绩报告表格数据
      result_personalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        scaleId: null,
        scaleTitle: null,
        userId: null,
        loginName: null,
        userName: null,
        countScore: null,
        factorScore: null,
        resultContent: null,
        factorResult: null,
        userAnswer: null,
        classesName: null,
        deptName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询所有人测评成绩报告列表 */
    getList() {
      this.loading = true;
      listResult_personal(this.queryParams).then((response) => {
        // console.log("111", response.rows);
        this.result_personalList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        resultId: null,
        scaleId: null,
        scaleTitle: null,
        userId: null,
        loginName: null,
        userName: null,
        countScore: null,
        factorScore: null,
        resultContent: null,
        factorResult: null,
        userAnswer: null,
        createTime: null,
        updateTime: null,
        classesName: null,
        deptName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.resultId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加个人测评成绩报告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const resultId = row.resultId || this.ids;
      getResult_personal(resultId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改测评成绩报告信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.resultId != null) {
            updateResult_personal(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addResult_personal(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const resultIds = row.resultId || this.ids;
      this.$modal
        .confirm(
          '是否确认删除个人测评成绩报告编号为"' + resultIds + '"的数据项？'
        )
        .then(function () {
          return delResult_personal(resultIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/result_personal/export",
        {
          ...this.queryParams,
        },
        `result_personal_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.myTooltips {
  background-color: rgb(108, 195, 230) !important;
  color: #fff;
  border: 1px solid #333;
  max-width: 30%;
  text-indent: 2em;
}
</style>
